package logic

import (
	"context"
	"transaction/tranrpc/tranrpc"

	"transaction/api/internal/svc"
	"transaction/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAddApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddApiLogic {
	return &UserAddApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAddApiLogic) UserAddApi(req *types.UserAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.TranRpc.UserAdd(l.ctx, &tranrpc.UserAddRequest{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
